package com.zhoukx.singleton.type3;

/**
 * @ClassName SingletonTest03
 * @Description:    懒汉式  （线程不安全的）
 * @Author zhoukx
 * @Date 2020/8/6
 **/
public class SingletonTest03 {
    public static void main(String[] args) {
     Singleton instance = Singleton.getInstance();
        Singleton instance2 = Singleton.getInstance();
        System.out.println("instance:"+instance.hashCode());
        System.out.println("instance2:"+instance2.hashCode());
    }
}
class  Singleton{

    private static Singleton  instance;

    private  Singleton(){

    }
    // 提供一个静态的公有方法，当使用该方法，才去创建
    public static  Singleton getInstance(){
        if (instance == null) {
            instance =   new Singleton();
        }
        return  instance;
    }
}
